package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.DTO.EmployeeDTO;
import com.sky.anno.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumclass.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 新增员工
     *
     * @param employee
     */
    @AutoFill(operationType = OperationType.INSERT,description = "新增操作的自动填充")
    @Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user)" +
            " VALUE " +
            "(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void saveEmployee(Employee employee);

    /**
     * 分页查询员工
     *
     * @param employeePageQueryDTO
     */
    //@Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where name=#{name}")
    Page<Employee> page(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 更新员工状态
     * @param employee
     */
    //@Update("update employee set status = #{status} where id = #{id}")
    @AutoFill(operationType = OperationType.UPDATE,description = "更新操作的自动填充")
    void updateStatus(Employee employee);
    //@Update("update employee set name = #{name}, username = #{username}, password = #{password}, phone = #{phone}, sex = #{sex}, id_number = #{idNumber}, status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @AutoFill(operationType = OperationType.UPDATE,description = "更新操作的自动填充")
    void updateEmployee(Employee employee);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where id = #{id}")
    Employee get(Long id);
    @Delete("delete from employee where id = #{id}")
    void delete(Long id);

    /**
     * 根据用户id修改密码
     * @param employee
     */
    @Update("update employee set password = #{password} where id = #{id}")
    void updatePassword(Employee employee);



}
